// 分类信息相关的api接口函数相关的对象
import request from "@/utils/request";
const API_NAME = "/admin/product";
export default {
  // GET /admin/product/getCategory1
  // getCategory1
  // 获取一级分类
  getCategoryList1() {
    return request.get(`${API_NAME}/getCategory1`);
  },
  // GET /admin/product/getCategory2/{category1Id}
  // getCategory2
  // 获取二级分类
  getCategoryList2(category1Id) {
    return request.get(`${API_NAME}/getCategory2/${category1Id}`);
  },
  // GET /admin/product/getCategory3/{category2Id}
  // getCategory3
  // 获取三级分类
  getCategoryList3(category2Id) {
    return request.get(`${API_NAME}/getCategory3/${category2Id}`);
  },
  // POST /admin/product/inner/findBaseCategory3ByCategory3IdList
  // findBaseCategory3ByCategory3IdList

  // DELETE /admin/product/removeCategory1/{id}
  // 删除一级分类
  // 删除一级分类
  deleteCategory1(id) {
    return request.delete(`${API_NAME}/removeCategory1/${id}`);
  },
  // DELETE /admin/product/removeCategory2/{id}
  // 删除二级分类
  deleteCategory2(id) {
    return request.delete(`${API_NAME}/removeCategory2/${id}`);
  },
  // DELETE /admin/product/removeCategory3/{id}
  // 删除三级分类
  deleteCategory3(id) {
    return request.delete(`${API_NAME}/removeCategory3/${id}`);
  },
  deleteCategory1OrCategory2OrCategory3(category) {
    const { level, id } = category;
    if (level === 1) {
      return this.deleteCategory1(id);
    } else if (level === 2) {
      return this.deleteCategory2(id);
    } else if (level === 3) {
      return this.deleteCategory3(id);
    }
  },
  // POST /admin/product/saveCategory1
  // 新增一级分类
  saveCategory1(category1) {
    return request.post(`${API_NAME}/saveCategory1`, category1);
  },
  // POST /admin/product/saveCategory2
  // 新增二级分类
  saveCategory2(category2) {
    return request.post(`${API_NAME}/saveCategory2`, category2);
  },
  // POST /admin/product/saveCategory3
  // 新增三级分类
  saveCategory3(category3) {
    return request.post(`${API_NAME}/saveCategory3`, category3);
  },
  saveCategory1OrCategory2OrCategory3(category) {
    const { level, id, name } = category;
    if (level === 1) {
      return this.saveCategory1({ name });
    } else if (level === 2) {
      return this.saveCategory2({ name, category1Id: id });
    } else if (level === 3) {
      return this.saveCategory3({ name, category2Id: id });
    }
  },
  // PUT /admin/product/updateeCategory1
  // 修改一级分类
  updateCategory1(category1) {
    return request.put(`${API_NAME}/updateeCategory1`, category1);
  },
  // PUT /admin/product/updateeCategory2
  // 修改二级分类
  updateCategory2(category2) {
    return request.put(`${API_NAME}/updateeCategory2`, category2);
  },
  // PUT /admin/product/updateeCategory3
  // 修改三级分类
  updateCategory3(category3) {
    return request.put(`${API_NAME}/updateeCategory3`, category3);
  },
  updateCategory1OrCategory2OrCategory3(category) {
    const { level, id, name } = category;
    if (level === 1) {
      return this.updateCategory1({ id, name });
    } else if (level === 2) {
      return this.updateCategory2({ id, name });
    } else if (level === 3) {
      return this.updateCategory3({ id, name });
    }
  },
};
